package com.foreveross.chameleon;

import android.content.Context;
import android.content.Intent;

import com.foreveross.chameleon.manager.CubeContentManager;
import com.foreveross.chameleon.manager.R;
import com.foreveross.chameleonsdk.CModule;
import com.foreveross.data.DataProvider;
import com.foreveross.push.OriginalParser;
import com.foreveross.push.client.NotificationPacketListener;
import com.foreveross.push.client.NotificationService;

public class CManagerModule	extends CModule{

	
	private Context context;
	

	@Override
	public void onCreate(CModule cModule) {
		super.onCreate(cModule);
//		AppStatus.USERLOGIN = false;
		init();
		readConfig(R.raw.pushmodule);
		NotificationPacketListener.register(new OriginalParser(context));
	}
	
	private void init() {
		context =getCApplication().getContext(); 
		DataProvider.getInstance(context, "cube");
		CubeContentManager contentManager = CubeContentManager.getInstance();
		contentManager.loadCubeContent(context);
		String token = CheckInUtil.createMD5Token(context);
		
		Intent intent =new Intent();
		intent.putExtra(NotificationService.ACTION, NotificationService.ACTION_CONNECT_XMPP);
		intent.putExtra(NotificationService.KEY_PASSWORD, token);
		intent.putExtra(NotificationService.KEY_USERNAME, token);
		intent.setClass(context, NotificationService.class);
		context.startService(intent);
		
	}
	
	
	public String getActivity(){
		return "com.foreveross.chameleon.CManagerModuleActivity";
	}	
	
	@Override
	public void onExit(CModule cModule) {
		super.onExit(cModule);
		CubeContentManager.getInstance().stopTask();
		CubeContentManager.getInstance().destory();
	}
	
	
	
	
}
